<?php

namespace app\admin\model\pt;

use think\Model;

class JobOffer extends Model
{
    // 表名
    protected $name = 'pt_job_offer';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'offer_status_text',
        'position_text'
    ];

    public function getJobOfferPositionList()
    {
        return [
            1 => '组长',
            2 => '图像员',
            3 => '资料员',
            4 => '申报员',
            5 => '写作员',
            6 => '业绩专员',
            7 => '继续教育',
            8 => '科研',
            9 => '专利',
            10 => '软著',
            11 => '论文'
        ];
    }

    public function getJobOfferStatusList()
    {
        return [

            1 => '待处理',
            2 => '同意接收',
            3 => '拒绝接收'
        ];
    }

    /**
     * 获取状态文本
     */
    public function getOfferStatusTextAttr($value, $data)
    {
        $statuses = [
            1 => '待处理',
            2 => '同意接收',
            3 => '拒绝接收'
        ];
        return isset($statuses[$data['offer_status']]) ? $statuses[$data['offer_status']] : '未知';
    }

    /**
     * 获取职位文本
     */
    public function getPositionTextAttr($value, $data)
    {
        $positions = [
            1 => '组长',
            2 => '图像员',
            3 => '资料员',
            4 => '申报员',
            5 => '写作员',
            6 => '业绩专员',
            7 => '继续教育',
            8 => '科研',
            9 => '专利',
            10 => '软著',
            11 => '论文'
        ];
        return isset($positions[$data['position']]) ? $positions[$data['position']] : '未知';
    }

    public function getJobOfferResponsibilityList()
    {
        return [
            0 => '次责',
            1 => '主责'
        ];
    }

    /**
     * 关联用户
     */
    public function user()
    {
        return $this->belongsTo('app\admin\model\Admin', 'user_id', 'id');
    }

    /**
     * 关联订单
     */
    public function order()
    {
        return $this->belongsTo('app\admin\model\pt\Order', 'order_id', 'id');
    }

    /**
     * 关联工人
     */
    public function worker()
    {
        return $this->belongsTo('app\admin\model\Admin', 'worker_id', 'id');
    }
}